package cn.ac.siom.query.dao.impl;

import cn.ac.siom.query.dao.Ikjjggs_newsDAO;
import cn.ac.siom.query.vo.kjjggs_news;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Repository
public class Kjjggs_newsDAOImpl extends SqlSessionDaoSupport implements Ikjjggs_newsDAO {
    @Autowired
    public Kjjggs_newsDAOImpl(SqlSessionFactory sqlSessionFactory){
        super.setSqlSessionFactory(sqlSessionFactory);
    }

    @Override
    public List<kjjggs_news> findByParams(Map params) throws Exception {
        return super.getSqlSession().selectList("kjjggs_newsNS.findByParams",params);
    }

    @Override
    public boolean doCreate(kjjggs_news vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doUpdate(kjjggs_news vo) throws SQLException {
        return false;
    }

    @Override
    public boolean doRemove(Set<?> ids) throws SQLException {
        return false;
    }

    @Override
    public kjjggs_news findById(Integer id) throws SQLException {
        return null;
    }

    @Override
    public List<kjjggs_news> findAll() throws SQLException {
        return super.getSqlSession().selectList("kjjggs_newsNS.findAll");
    }

    @Override
    public List<kjjggs_news> findAllBySplit(String column, String keyWord, Integer currentPage, Integer lineSize) throws SQLException {
        return null;
    }

    @Override
    public List<kjjggs_news> findNo(Integer id ) throws SQLException {
        Map<String, Integer> map= new HashMap<>();
        map.put("i_id",id);
        return super.getSqlSession().selectList("kjjggs_newsNS.findNo", map);
    }

    @Override
    public List<kjjggs_news> findPage(Integer rownum,Integer page_id) throws SQLException {
        page_id=rownum*(page_id-1);
        Map<String, Integer> map= new HashMap<>();
        map.put("page_id",page_id);
        map.put("rownum",rownum);
        return super.getSqlSession().selectList("kjjggs_newsNS.findPage", map);
    }

    @Override
    public Integer findCount(Map map) throws SQLException {
        return super.getSqlSession().selectOne("kjjggs_newsNS.findCount",map);
    }

    @Override
    public String findPhoto(Integer i_id) throws SQLException {
        Map map=new HashMap<>();
        map.put("i_id",i_id);
        return super.getSqlSession().selectOne("kjjggs_newsNS.findPhoto", map);
    }

    @Override
    public boolean insert(kjjggs_news vo) throws SQLException {
        return super.getSqlSession().insert("kjjggs_newsNS.doInsert",vo)>0;
    }

    @Override
    public boolean update(kjjggs_news vo) throws SQLException {
        return super.getSqlSession().update("kjjggs_newsNS.doUpdate",vo) >0;
    }


    @Override
    public boolean delete(List<String> ids) throws SQLException {
        return super.getSqlSession().update("kjjggs_newsNS.doDelete",ids) >0;
    }

}
